package com.tebiecloud.base.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tebiecloud.base.client.model.entity.BaseUser;
import com.tebiecloud.base.server.service.BaseUserService;
import com.tebiecloud.base.server.service.feign.StoreServiceClient;
import com.tebiecloud.common.model.ResultBody;
import com.tebiecloud.common.mybatis.query.CriteriaQuery;
import com.tebiecloud.common.utils.ResultBodyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统用户-管理员信息 前端控制器
 *
 * @author tebie
 * @date 2019-08-02
 */
@RestController
@RequestMapping("baseuser")
public class BaseUserController {

    @Autowired
    private BaseUserService baseUserService;

    @Autowired
    StoreServiceClient storeServiceClient;

    /**
     * 获取AGM列表
     *
     * @param phone
     * @param number
     * @param name
     * @param status
     * @param minct
     * @param maxct
     * @return
     */
    @GetMapping(value = "/listAgm")
    public ResultBody<IPage<BaseUser>> list(
            @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
            @RequestParam(value = "limit", defaultValue = "10", required = false) Integer limit,
            @RequestParam(value = "phone", required = false) String phone,
            @RequestParam(value = "number", required = false) String number,
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "minct", required = false) String minct,
            @RequestParam(value = "maxct", required = false) String maxct) {
        CriteriaQuery wrapper = new CriteriaQuery();

        baseUserService.pageList(wrapper);

//        PageParams pageParams = new PageParams(map);
//        BaseUser query = pageParams.mapToObject(BaseUser.class);
//        QueryWrapper<BaseUser> queryWrapper = new QueryWrapper();
//        return ResultBodyUtils.ok(baseUserService.page(new PageParams(map), queryWrapper));
        return null;
    }

    /**
     * 添加agm用户表
     */
    @PostMapping("/add")
    public ResultBody add(@RequestParam("username") String username,
                          @RequestParam("provincesIn") String provincesIn,
                          @RequestParam("avatar") String avatar,
                          @RequestParam("mobile") String mobile,
                          @RequestParam("sex") Integer sex,
                          @RequestParam("status") Integer status,
                          @RequestParam("birthday") String birthday,
                          @RequestParam("name") String name
    ) {
        BaseUser baseUsers = new BaseUser();
        baseUsers.setAvatar(avatar);
        baseUsers.setProvincesIn(provincesIn);
        baseUsers.setNickName(username);
        baseUsers.setMobile(mobile);
        baseUsers.setBirthday(birthday);
        baseUsers.setSex(sex);
        baseUsers.setStatus(status);
        baseUserService.save(baseUsers);
        storeServiceClient.select(name,username,mobile,sex,baseUsers.getUserId());
        return ResultBodyUtils.ok();
    }

//    /**
//     * 获取分页数据
//     * @param map
//     * @return
//     */
//    @GetMapping(value = "/list")
//    public ResultBody<IPage<BaseUser>> list(@RequestParam(required = false) Map map) {
//        PageParams pageParams = new PageParams(map);
//        BaseUser query = pageParams.mapToObject(BaseUser.class);
//        QueryWrapper<BaseUser> queryWrapper = new QueryWrapper();
//        return ResultBodyUtils.ok(baseUserService.page(new PageParams(map), queryWrapper));
//    }
//
//    /**
//     * 根据ID查找数据
//     * @param id
//     * @return
//     */
//    @GetMapping("/get")
//    public ResultBody<BaseUser> get(@RequestParam("id") Long id) {
//        BaseUser entity = baseUserService.getById(id);
//        return ResultBodyUtils.ok(entity);
//    }
//
//    /**
//     * 添加数据
//     * @param userName 登陆账号,
//     * @param nickName 昵称,
//     * @param avatar 头像,
//     * @param email 邮箱,
//     * @param mobile 手机号,
//     * @param userType 用户类型:super-超级管理员 normal-普通管理员,
//     * @param companyId 企业ID,
//     * @param userDesc 描述,
//     * @param status 状态:0-禁用 1-正常 2-锁定
//     * @return
//     */
//    @PostMapping("/add")
//    public ResultBody add(
//        @RequestParam(value = "userName", required = false) String userName,
//        @RequestParam(value = "nickName", required = false) String nickName,
//        @RequestParam(value = "avatar", required = false) String avatar,
//        @RequestParam(value = "email", required = false) String email,
//        @RequestParam(value = "mobile", required = false) String mobile,
//        @RequestParam(value = "userType", required = false) String userType,
//        @RequestParam(value = "companyId", required = false) Long companyId,
//        @RequestParam(value = "userDesc", required = false) String userDesc,
//        @RequestParam(value = "status", required = false) Integer status
//    ) {
//        BaseUser entity = new BaseUser();
//        entity.setUserName(userName);
//        entity.setNickName(nickName);
//        entity.setAvatar(avatar);
//        entity.setEmail(email);
//        entity.setMobile(mobile);
//        entity.setUserType(userType);
//        entity.setCompanyId(companyId);
//        entity.setUserDesc(userDesc);
//        entity.setStatus(status);
//        baseUserService.save(entity);
//        return ResultBodyUtils.ok();
//    }
//
//    /**
//     * 更新数据
//     * @param userName 登陆账号
//     * @param nickName 昵称
//     * @param avatar 头像
//     * @param email 邮箱
//     * @param mobile 手机号
//     * @param userType 用户类型:super-超级管理员 normal-普通管理员
//     * @param companyId 企业ID
//     * @param userDesc 描述
//     * @param status 状态:0-禁用 1-正常 2-锁定
//     * @return
//     */
//    @PostMapping("/update")
//    public ResultBody update(
//            @RequestParam(value = "userId", required = false) Long userId,
//            @RequestParam(value = "userName", required = false) String userName,
//            @RequestParam(value = "nickName", required = false) String nickName,
//            @RequestParam(value = "avatar", required = false) String avatar,
//            @RequestParam(value = "email", required = false) String email,
//            @RequestParam(value = "mobile", required = false) String mobile,
//            @RequestParam(value = "userType", required = false) String userType,
//            @RequestParam(value = "companyId", required = false) Long companyId,
//            @RequestParam(value = "userDesc", required = false) String userDesc,
//            @RequestParam(value = "status", required = false) Integer status
//    ) {
//        BaseUser entity = new BaseUser();
//        entity.setUserId(userId);
//        entity.setUserName(userName);
//        entity.setNickName(nickName);
//        entity.setAvatar(avatar);
//        entity.setEmail(email);
//        entity.setMobile(mobile);
//        entity.setUserType(userType);
//        entity.setCompanyId(companyId);
//        entity.setUserDesc(userDesc);
//        entity.setStatus(status);
//        baseUserService.updateById(entity);
//        return ResultBodyUtils.ok();
//    }
//
//    /**
//     * 删除数据
//     * @param id 单个id
//     * @param ids 多个id用,号隔开
//     * @return
//     */
//    @PostMapping("/remove")
//    public ResultBody remove(
//            @RequestParam(value = "id", required = false) Long id,
//            @RequestParam(value = "ids", required = false) String ids
//    ) {
//        if(id != null && id > 0) {
//            baseUserService.removeById(id);
//        }
//        if(ids != null && ids.length() > 0) {
//            baseUserService.removeByIds(Arrays.asList(ids.split(",")));
//        }
//        return ResultBodyUtils.ok();
//    }

}
